﻿This is a project I completed for a computer graphics class. Everything is written from scratch using Java and a wrapper for OpenGL. The shaders were also written by me in GLSL. The project asked that we import and read a model and display it in a scene using a skybox and light the scene using a point light. This is the report that details how I completed these tasks. 
Project 3: Lights, materials, textures, and skyboxes (Tron)


Problem:
In this project, I was tasked with creating my own scene of three or more textured objects. One of these objects needed to be a .obj file that has been imported into our program. These objects need to be illuminated by a global ambient light that is always on and a positional light that can be turned on and off. The lights could use either the Phong or Blinn-Phong model for lighting, and a yellow cube or point should be drawn at the position of the light. Finally, there needs to be a skybox that envelops the scene and can be seen in the background. 


Solution:


Goal
In starting this project, I hoped to recreate an iconic image of early computer graphics in film in the form of the Tron light cycle scene. The light cycle was originally made using primitive shapes and boolean operations, however here I am simply importing a model that I found online. The rest of the assets, including the texture images for the light cycles, were made by me. 


Imported Models and Skybox
I first started by importing models into the scene. I used the ImportedModel class to read my .obj files and collect the point, texture, and normal data from the model. This data is then passed to the vertex shader using VBOs and the frag shader samples the given texture based on the texture coordinates. The skybox was rendered in the same manner except for two key differences. The first is that the depth test is disabled before the skybox is drawn. This is to ensure that the skybox appears to be in the distance. Secondly, the skybox is using a different rendering program than the models. This rendering program also samples the texture using the texture coordinates. This program’s vertex shader removes the translation-affecting column of the MVP matrix so that the skybox does not more with the camera. Additionally, I copied the code from the previous project to manipulate the camera within the scene by changing the view matrix using the lookAt function. 


Lighting and Shaders
The next task to complete was to put a positional light into the scene and have it influence the appearance of the models. The first step to this was setting up the lights in the java code by initializing the values of both the light's ambient, diffuse, and specular influence as well as the material’s ambient, diffuse, specular, and shininess. These values are all passed into the fragment shader through the vertex shader. Using the model’s normal vectors, the light position, and the light and material properties, the light’s influence on lighting the model can be calculated using the Phong model for lighting. After the ambient, diffuse, and specular lighting has been calculated, these values are added together. This is done by calculating a weighted sum using these values: 2* ambient, 1* diffuse, and 1*specular. The weighted sum is multiplied by the color from the texture to output the final color for each point. The spacebar will turn the positional light on and off by setting all of the light properties except the global ambient to 0,0,0. This allows the global ambient light to still illuminate the scene, but the models are not affected by the positional light. Additionally, I reused the light’s position and the cube vertex data to draw a yellow cube at the position of the light. 


